//
//  TSBaseCollectionView.swift
//  Pods
//
//  Created by 100Years on 2025/6/17.
//



public extension UICollectionView {
    
    public func getAllLoadedCells() -> [(UICollectionViewCell,IndexPath)] {
        var cells = [(UICollectionViewCell,IndexPath)]()
        
        // 遍历所有 section
        for section in 0..<self.numberOfSections {
            // 遍历所有 item
            for item in 0..<self.numberOfItems(inSection: section) {
                let indexPath = IndexPath(item: item, section: section)
                if let cell = self.cellForItem(at: indexPath) {
                    cells.append((cell,indexPath))
                }
            }
        }
        
        return cells
    }
    
}

open class TSBaseCollectionView: UICollectionView {
//    override var effectiveUserInterfaceLayoutDirection: UIUserInterfaceLayoutDirection {
//        return kIsRTL ? .rightToLeft : .leftToRight
//    }

    // MARK: - 初始化
    
    override public init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: layout)
        commonInit()
    }
    
    required public init?(coder: NSCoder) {
        super.init(coder: coder)
        commonInit()
    }
    
    // MARK: - 公共配置
    
    private func commonInit() {
        // 通用配置
        backgroundColor = .systemBackground
        keyboardDismissMode = .onDrag

        if kIsRTL {
            semanticContentAttribute = .forceRightToLeft
        }
        
        
        backgroundColor = .clear
        showsVerticalScrollIndicator = false
        showsHorizontalScrollIndicator = false
        if #available(iOS 11.0, *) {
            contentInsetAdjustmentBehavior = .never
        }
    }
    
}

open class TSBaseCollectionViewFlowLayout: UICollectionViewFlowLayout {
    open override var flipsHorizontallyInOppositeLayoutDirection: Bool {
        return kIsRTL
    }
}

